home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
WINSRC20.ZIP
/
DIALOG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-20
|
14KB
|
428 lines
/*
various dialog-box code - there's more in DIALOG2.C
*/
#include "windows.h"
#include "winfract.h"
#include "fractint.h"
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <sys\types.h>
#include <sys\stat.h>
extern HWND hwnd; /* handle to main window */
extern char szHelpFileName[]; /* Help file name*/
char DialogTitle[128];
char FileName[128];
char PathName[128];
char OpenName[128];
char DefPath[128];
char DefSpec[13];
char DefExt[10];
char str[255];
OFSTRUCT OfStruct; /* information from OpenFile() */
struct stat FileStatus; /* information from fstat() */
/****************************************************************************
FUNCTION: SaveAsDlg(HWND, unsigned, WORD, LONG)
PURPOSE: Allows user to change name to save file to
COMMENTS:
This will initialize the window class if it is the first time this
application is run. It then creates the window, and processes the
message loop until a PostQuitMessage is received. It exits the
application by returning the value passed by the PostQuitMessage.
****************************************************************************/
BOOL bSaveEnabled = FALSE;
extern int time_to_save;
int FAR PASCAL SaveAsDlg(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
char TempName[128];
switch (message) {
case WM_KEYDOWN:
switch (wParam) {
case VK_F1:
/* F1, shifted F1 bring up the Help Index */
WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
break;
}
case WM_INITDIALOG:
SetDlgItemText(hDlg, ID_FILETITLE, DialogTitle);
/* If no filename is entered, don't allow the user to save to it */
if (!FileName[0])
bSaveEnabled = FALSE;
else {
bSaveEnabled = TRUE;
/* Process the path to fit within the IDC_PATH field */
DlgDirList(hDlg, DefPath, NULL, IDC_PATH, 0x4010);
/* Send the current filename to the edit control */
SetDlgItemText(hDlg, IDC_EDIT, FileName);
/* Accept all characters in the edit control */
SendDlgItemMessage(hDlg, IDC_EDIT, EM_SETSEL, 0,
MAKELONG(0, 0x7fff));
}
/* Enable or disable the save control depending on whether the
* filename exists.
*/
EnableWindow(GetDlgItem(hDlg, IDOK), bSaveEnabled);
/* Set the focus to the edit control within the dialog box */
SetFocus(GetDlgItem(hDlg, IDC_EDIT));
return (FALSE); /* FALSE since Focus was changed */
case WM_COMMAND:
switch (wParam) {
case IDC_EDIT:
/* If there was previously no filename in the edit
* control, then the save control must be enabled as soon as
* a character is entered.
*/
if (HIWORD(lParam) == EN_CHANGE && !bSaveEnabled)
EnableWindow(GetDlgItem(hDlg, IDOK), bSaveEnabled = TRUE);
return (TRUE);
case IDOK:
/* Get the filename from the edit control */
GetDlgItemText(hDlg, IDC_EDIT, TempName, 128);
/* If there are no wildcards, then separate the name into
* path and name. If a path was specified, replace the
* default path with the new path.
*/
if (CheckFileName(hDlg, FileName, TempName)) {
SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
(LPSTR) FileName);
if (str[0])
strcpy(DefPath, str);
/* Tell the caller a filename was selected */
EndDialog(hDlg, IDOK);
time_to_save = 1;
}
return (TRUE);
case IDCANCEL:
/* Tell the caller the user canceled the SaveAs function */
EndDialog(hDlg, IDCANCEL);
time_to_save = 1;
return (FALSE);
}
break;
}
return (FALSE);
}
/****************************************************************************
FUNCTION: OpenDlg(HWND, unsigned, WORD, LONG)
PURPOSE: Let user select a file, and return. Open code not provided.
****************************************************************************/
HANDLE FAR PASCAL OpenDlg(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
WORD index;
PSTR pTptr;
HANDLE hFile=1; /* Temp value for return */
switch (message) {
case WM_KEYDOWN:
switch (wParam) {
case VK_F1:
/* F1, shifted F1 bring up the Help Index */
WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
break;
}
case WM_COMMAND:
switch (wParam) {
case IDC_LISTBOX:
switch (HIWORD(lParam)) {
case LBN_SELCHANGE:
/* If item is a directory name, append "*.*" */
if (DlgDirSelect(hDlg, str, IDC_LISTBOX))
strcat(str, DefSpec);
SetDlgItemText(hDlg, IDC_EDIT, str);
SendDlgItemMessage(hDlg,
IDC_EDIT,
EM_SETSEL,
NULL,
MAKELONG(0, 0x7fff));
break;
case LBN_DBLCLK:
goto openfile;
}
return (TRUE);
case IDOK:
openfile:
GetDlgItemText(hDlg, IDC_EDIT, OpenName, 128);
if (strchr(OpenName, '*') || strchr(OpenName, '?')) {
SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
(LPSTR) OpenName);
if (str[0])
strcpy(DefPath, str);
ChangeDefExt(DefExt, DefSpec);
UpdateListBox(hDlg);
return (TRUE);
}
if (!OpenName[0]) {
MessageBox(hDlg, "No filename specified.",
NULL, MB_OK | MB_ICONHAND);
return (TRUE);
}
AddExt(OpenName, DefExt);
strcpy(FileName, OpenName);
/* The routine to open the file would go here, and the */
/* file handle would be returned instead of NULL. */
EndDialog(hDlg, hFile);
return (TRUE);
case IDCANCEL:
EndDialog(hDlg, NULL);
return (FALSE);
}
break;
case WM_INITDIALOG: /* message: initialize */
UpdateListBox(hDlg);
SetDlgItemText(hDlg, ID_FILETITLE, DialogTitle);
SetDlgItemText(hDlg, IDC_EDIT, DefSpec);
SendDlgItemMessage(hDlg, /* dialog handle */
IDC_EDIT, /* where to send message */
EM_SETSEL, /* select characters */
NULL,